package com.audaque.springboot.foshanupload.web.redisdemo.controller;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author zgb
 * @desc ...
 * @date 2021-12-26 20:13:36
 */
@RestController
@RequestMapping("luaOpt")
public class LuaOptController {
    @Resource(name = "set")
    private DefaultRedisScript<Boolean> redisScriptSet;
    @Resource(name = "del")
    private DefaultRedisScript<Boolean> redisScriptDel;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/redisScriptSet")
    public ResponseEntity redisScriptSet() {
        List<String> keys = Arrays.asList("testLua", "hello lua");
        Boolean execute = stringRedisTemplate.execute(redisScriptSet, keys, "100");
        return null;
    }

    @GetMapping("/redisScriptDel")
    public ResponseEntity redisScriptDel(String key) {
        List<String> keys = Arrays.asList(key);
        Boolean execute = stringRedisTemplate.execute(redisScriptDel, keys);
        return null;
    }
}
